package org.cttic.visualization.visualization.z_service.first;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import org.cttic.visualization.visualization.util.ResponseObject;
import org.cttic.visualization.visualization.z_service.MarkTriggerTopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class MarkTriggerTopServiceImpl implements MarkTriggerTopService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public ResponseObject triggerTop(JSONObject json) {

        String provinceId = json.getStr("provinceId");
        JSONObject all = this.findAll();
        return ResponseObject.success(all);


//        JSONObject response = new JSONObject();
//
//
//        List<JSONObject> lists = new ArrayList<>();
//
//        String sql = " SELECT '3' pointType,provinceId  gantryId,provinceName gantryName," +
//            "totalCount totalCount  FROM  stationCount ORDER BY totalCount desc";
//        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
//
//        int rank = 1;
//        for (Map<String, Object> map : maps) {
//
//            JSONObject jsonObject = new JSONObject();
//            jsonObject.put("rank",rank +"");
//            jsonObject.put("gantryId",map.get("gantryId").toString());
//            jsonObject.put("gantryName",map.get("gantryName"));
//            jsonObject.put("totalCount",map.get("totalCount").toString());
//            jsonObject.put("pointType",map.get("pointType"));
//
//            lists.add(jsonObject);
//            rank++;
//        }
//
//        response.put("rankingArray",lists);
//        return ResponseObject.success(response);
    }


    private  JSONObject findAll(){
        JSONObject response = new JSONObject();
        List<JSONObject> lists = new ArrayList<>();

        String sql = " SELECT '3' pointType,provinceId  gantryId,provinceName gantryName," +
            "totalCount totalCount  FROM  stationCount ORDER BY totalCount desc";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);

        int rank = 1;
        for (Map<String, Object> map : maps) {

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("rank",rank +"");
            jsonObject.put("gantryId",map.get("gantryId").toString());
            jsonObject.put("gantryName",map.get("gantryName"));
            jsonObject.put("totalCount",map.get("totalCount").toString());
            jsonObject.put("pointType",map.get("pointType"));

            lists.add(jsonObject);
            rank++;
        }

        response.put("rankingArray",lists);

        return response;
    }



    
}
